﻿//Copyright (C) <2013>  <jonathan cleeve norton> All Rights Reserved 
//Contact jon.norton@fin-plus.co.uk website <http://www.fin-plus.co.uk/>
using System;
using FinPlusInterfaces;
using FinPlusAssembler;

namespace FinPlusCompView
{
    public partial class FinPlusColValueShiftButton : FinPlusControl
    {
        [State(Test = true)]
        public override bool IsValid { get; set; }
        public event EventHandler<IPod> ColShift;
        
        //construct
        public FinPlusColValueShiftButton(string shift)
        {
            InitializeComponent();
            colShift.Content = Id = shift.Split(',')[0];
            Tag = shift;
            IsValid = true;
        }

        //common control interface
        public override void CmdExecute(IPod command)
        {
            try
            {
                CmdCapture(command);

                switch ((Cmds)Enum.Parse(typeof(Cmds), command.Name, true))
                {
                    case Cmds.ColValueShiftUp: 
                    case Cmds.ColValueShiftDown:
                    case Cmds.ColValShiftLevel: ColShift.Invoke(this, command); break;
                    default: throw new Exception(string.Format("cmd not recognised {0}", command.Name));
                }
            }
            catch (CmdExecuteException e)
            {
                IsValid = Level.Warning.Log(Id, Config, e.Message, e);
            }
        }

        //cmds
        private enum Cmds { ColValueShiftUp, ColValueShiftDown, ColValShiftLevel }
   }
}
